package com.example.wangfanwangluo.wangfanboss.Adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.wangfanwangluo.wangfanboss.Models.KucunDetailModel;
import com.example.wangfanwangluo.wangfanboss.R;

import java.util.List;

/**
 * Created by wanghouyi on 2017/11/28.
 */

public class KucunDetailAdapter extends BaseAdapter {


    private Context context;
    private List<KucunDetailModel> list;
    private KucunDetailModel model;
    public KucunDetailAdapter(Context context,List<KucunDetailModel> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public KucunDetailModel getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        model = getItem(position);
        View view;
        ViewHolder viewHolder;
        if (convertView == null) {
            view = LayoutInflater.from(context).inflate(R.layout.adapter_kucun_detail, parent, false);
            viewHolder = new ViewHolder();
            viewHolder.goodsID = (TextView)view.findViewById(R.id.kucun_detail_item_id);
            viewHolder.num = (TextView)view.findViewById(R.id.kucun_detail_item_num);
            viewHolder.goodsStatus = (TextView)view.findViewById(R.id.kucun_detail_item_status);
            viewHolder.cost = (TextView)view.findViewById(R.id.kucun_detail_item_cost);
            viewHolder.goodsInfo = (TextView)view.findViewById(R.id.kucun_detail_item_goods);
            viewHolder.detailAction = (TextView)view.findViewById(R.id.kucun_detail_item_detail);

            view.setTag(viewHolder);
        }else {
            view = convertView;
            viewHolder = (ViewHolder)view.getTag();
        }

        viewHolder.goodsID.setText(model.getGoodsID());
        viewHolder.num.setText(model.getNum());
        viewHolder.goodsStatus.setText("【"+model.getGoodsStatus()+"】");
        viewHolder.cost.setText("运费："+model.getCost()+"元");
        viewHolder.goodsInfo.setText("货物：" + model.getGoodsName() + "（" + model.getWeight() + "吨，" +
                model.getVolum() + "方，" + model.getCount() + "件"+ "）");
        viewHolder.detailAction.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                objOnDetailPushListener.onDetailPushListener(position);
            }
        });
        return view;
    }

    public interface onDetailPushListener {
        void onDetailPushListener(int i);
    }

    private onDetailPushListener objOnDetailPushListener;

    public void setObjOnDetailPushListener(onDetailPushListener objOnDetailPushListener) {
        this.objOnDetailPushListener = objOnDetailPushListener;
    }


    class ViewHolder {
        TextView num;
        TextView goodsID;
        TextView goodsStatus;
        TextView cost;
        TextView goodsInfo;
        TextView detailAction;
    }
}
